var layerLoad;
    var dataAxis;
    var data;
    var yMax;//y轴最大值
    var dataShadow = [];
    // 使用刚指定的配置项和数据显示图表。
    // Enable data zoom when user click bar.
    var zoomSize = 6;

var chartAjaxFlog=1;
var myChart;
function chartAjax(){
    /*空日期判定*/
    /*if(chartAjaxFlog !== 0){
        if($("#my-startDate").text()===""||$('#my-endDate').text()===""){
            layer.msg('日请选择正确的日期', {icon: 2});
            chartAjaxFlog=2;
        }else{
            chartAjaxFlog=3;
        }
    }else{
        chartAjaxFlog=1;
    }
    if(chartAjaxFlog===2){
        return
    }*/
    if(chartAjaxFlog===0){
        layer.msg('请选择正确的日期', {icon: 2});
        return
    }
    var sysProductType = {
        areaType : $("#areaType").val(),
        endTime:$("#my-endDate").val(),
        startTime:$("#my-startDate").val()
    };
    var chartTitl="";
    if($("#chartType").val()=="thermodynamicChartForReceiverTotal"){
        chartTitl="(人)"
    }else if($("#chartType").val()=="thermodynamicChartForOrderTotal"){
        chartTitl="(单)"
    }else if($("#chartType").val()=="thermodynamicChartForAmountTotal"){
        chartTitl="(元)"
    }
    var titlTxt=$("#areaType :selected").text()+$("#chartType :selected").text()+"热力图"+chartTitl;
    $.ajax({
        url : $api.thermodynamic[$("#chartType").val()],
        type : "POST",
        dataType : "JSON",
        contentType : 'application/json',
        data:JSON.stringify(sysProductType),
        beforeSend : function () {
            layerLoad = layer.load();
        },
        success : function(data2,e) {
            if(!$checkRemouteStatus(data2)){
                layer.close(layerLoad);
                return;
            }
            layer.close(layerLoad);
            dataAxis=data2[0];
            data=data2[1];
            if(dataAxis.length===0||data.length===0){
                layer.msg('该时段无订单', {icon: 2});
                myChart.clear();
                return
            };
            yMax=Math.max.apply(null, data)+20;
            var option ={
                title: {
                    text:titlTxt,
                },
                xAxis: {
                    data: dataAxis,
                    axisLabel: {
                        show:true,
                        textStyle: {
                            color: '#000'
                        }
                    },
                    axisTick: {
                        show: true,
                    },
                    axisLine: {
                        show: false
                    },
                    z: 10
                },
                yAxis: {
                    axisLine: {
                        show: false
                    },
                    axisTick: {
                        show: false
                    },
                    axisLabel: {
                        textStyle: {
                            color: '#999'
                        }
                    }
                },
                series: [
                    {
                        type: 'bar',
                        barWidth:'50',
                        itemStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(
                                    0, 0, 0, 1,
                                    [
                                        {offset: 0, color: '#83bff6'},
                                        {offset: 0.5, color: '#188df0'},
                                        {offset: 1, color: '#188df0'}
                                    ]
                                )
                            },
                            emphasis: {
                                color: new echarts.graphic.LinearGradient(
                                    0, 0, 0, 1,
                                    [
                                        {offset: 0, color: '#2378f7'},
                                        {offset: 0.7, color: '#2378f7'},
                                        {offset: 1, color: '#83bff6'}
                                    ]
                                )
                            }
                        },
                        label:{
                            emphasis:{
                                show:true,
                                position: "top",
                                textStyle:{
                                    color:'#000',
                                    fontWeight:'500'
                                },
                            },
                            normal:{
                                show:true,
                                position: "top",
                                textStyle:{
                                    color:'#000',
                                    fontWeight:'500'
                                },
                            }
                        },
                        data: data
                    }
                ]
            };
            //myChart.clear();
            myChart = echarts.init(document.getElementById('echarts'));
            myChart.setOption(option);
        },
        error : function() {
            layer.close(layerLoad);
            layer.msg('网络异常，请稍后再试', {icon: 2});
        }
    });
};
chartAjax();
/*日期*/
$(function() {
    //new Date(new Date().getTime().toLocaleDateString().replace(/\//g,"-"));
    var startDate = new Date(new Date().getTime()-30*86400000).toLocaleDateString().replace(/\//g,"-");
    var endDate = new Date().toLocaleDateString().replace(/\//g,"-");
    var $alert = $('#my-alert');
    $('#my-startDate').datepicker().on('changeDate.datepicker.amui', function(event) {
        if (event.date.valueOf() >= endDate.valueOf()) {
            $alert.find('p').text('开始日期应小于结束日期！').end().show();
            chartAjaxFlog=0;
        } else {
            chartAjaxFlog=1;
            $alert.hide();
            startDate = new Date(event.date);
            //$('#my-startDate').val($('#my-startDate').data('date'));
        }
        $('#my-startDate').datepicker('close');
    });
    $('#my-endDate').datepicker().on('changeDate.datepicker.amui', function(event) {
        if (event.date.valueOf() <= startDate.valueOf()) {
            $alert.find('p').text('结束日期应大于开始日期！').end().show();
            chartAjaxFlog=0;
        } else {
            chartAjaxFlog=1;
            $alert.hide();
            endDate = new Date(event.date);
            //$('#my-endDate').val($('#my-endDate').data('date'));
        }
        $('#my-endDate').datepicker('close');
    });
});

function cleanData(){
    $("#my-startDate")[0].value="";
    $("#my-endDate")[0].value="";
};

